/**
 * @description Model Manifest
 *
 * @author Xiongmao
 */

var db = require('../db');

module.exports = db.model('Department', {
    tableName: 'departments',
    hasTimestamps: true,
    members() {
        return this.hasMany('User', 'department_id');
    },
    nums() {
        return this.hasMany('Repair', 'department_id')
        .query(qb => {
            qb.count('id as count');
            qb.select('id', 'status');
            qb.orderBy('status');
            qb.groupBy('status', 'department_id');
        });
    }
});
